package xyz.xtt.asset.vo;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;

import com.alibaba.cloud.commons.lang.StringUtils;

import cn.hutool.core.util.IdUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class AllUserPushMessageRequest {

	/**
	 * 消息 id
	 */
	private String messageId;

	/**
	 * 消息 title 暂时不传
	 */
	private String title;

	/**
	 * 消息内容
	 */
	private String content;

	/**
	 * 链接
	 */
	private String link;

	/**
	 * 时间戳
	 */
	private Instant expiredAt;

	/**
	 * 图片url
	 */
	private String picUrl;

	/**
	 * 选折发送着类型 1=小通通
	 */
	private Integer sendUserType;

	/**
	 * 消息类型 1=文本/连接 2=图文
	 */
	private Integer messageType;

	/**
	 * 用户类型；当用户类型等于1时，就代表全部用户发送，listUserId传null;当选折部分用户时，userType=0，listUserId传值
	 */
	private Integer userType;

	/**
	 * 用户id集合
	 */
	private List<Long> listUserId;

	public static AllUserPushMessageRequest buildParam(String title, Integer expiredAtDay, String content, String picUrl, List<Long> targetUids) {
		Instant expiredAt = LocalDateTime.now().plusDays(expiredAtDay).toInstant(ZoneOffset.UTC);
		return AllUserPushMessageRequest
				.builder()
				.messageId(IdUtil.getSnowflakeNextIdStr())
				.title(title)
				.content(content)
				.link(StringUtils.EMPTY)
				.expiredAt(expiredAt)
				.picUrl(picUrl)
				.sendUserType(1)
				.messageType(1)
				.userType(0)
				.listUserId(targetUids)
				.build();
	}

}
